﻿package com.badibadi.adapter;

import com.badibadi.activity.LoginActivity;
import com.badibadi.activity.LogoActivity;
import com.badibadi.activity.RegirstrationActivity;
import com.badibadi.mytools.DisplayUtil;
import com.badibadi.mytools.Utils;
import com.badibadi.uniclubber.R;

import android.R.integer;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.GradientDrawable.Orientation;
import android.os.AsyncTask;
import android.os.Handler;
import android.sax.StartElementListener;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.AbsListView.LayoutParams;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListAdapter;
import android.widget.TextView;

public class BeforeLandingPageAdapter extends BaseAdapter {

	/**
	 * 是否有更新
	 */
	private boolean HasUpdate = true;
	TextView news;
	private int Child_Img1[] = { R.drawable.ic_launcher,
			R.drawable.ic_launcher, R.drawable.b1, R.drawable.b2,
			R.drawable.b3,

			R.drawable.b4, R.drawable.b5, R.drawable.ic_launcher,
			R.drawable.b6, R.drawable.b7, R.drawable.b8,// R.drawable.b9,
			R.drawable.b10, R.drawable.b11, R.drawable.b12,

	};
	Context context;

	private String[] item = null;

	public BeforeLandingPageAdapter(Context ct) {
		context = ct;

		item = new String[] {
				"",
				context.getResources().getString(R.string.clubs),
				context.getResources().getString(R.string.homepage),
				context.getResources().getString(R.string.club),
				context.getResources().getString(R.string.activity),
				context.getResources().getString(R.string.ADayToRemember),
				context.getResources().getString(R.string.BuyingOffice),
				context.getResources().getString(R.string.Set),
				context.getResources().getString(R.string.ClearTheCache),
				context.getResources().getString(R.string.UpDate),
				context.getResources().getString(R.string.Feedback),
				// context.getResources().getString(R.string.LanguageSwitching),
				context.getResources().getString(R.string.UseTheHelp),
				context.getResources().getString(R.string.AboutUs),
				context.getResources().getString(R.string.PrivacyStatement), };
		HasUpdate = Utils.isGenXin(context);
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return item.length;
	}

	@Override
	public Object getItem(int postion) {
		// TODO Auto-generated method stub
		return item[postion];
	}

	@Override
	public long getItemId(int postion) {
		// TODO Auto-generated method stub
		return postion;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup arg2) {
		// TODO Auto-generated method stub

		LayoutInflater layoutInflater;
		LinearLayout l3;
		View v;
		switch (position) {
		case 0:
			layoutInflater = LayoutInflater.from(context);
			convertView = layoutInflater.inflate(
					R.layout.before_landing_and_regirstration, null);
			Button login_button = (Button) convertView
					.findViewById(R.id.before_landing_login);
			Button registration = (Button) convertView
					.findViewById(R.id.before_landing_regirstration);
			login_button.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					Intent intent = new Intent(context, LoginActivity.class);
					context.startActivity(intent);

				}
			});
			registration.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					Intent intent2 = new Intent(context,
							RegirstrationActivity.class);
					context.startActivity(intent2);
				}
			});
			LinearLayout ll = new LinearLayout(context);
			ll.setOrientation(LinearLayout.VERTICAL);
			ll.setLayoutParams(new AbsListView.LayoutParams(
					LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
			ll.setGravity(Gravity.CENTER_HORIZONTAL);
			ll.addView(convertView);

			// android:layout_marginLeft="10dp"

			return ll;

		case 1:
			LinearLayout l1 = new LinearLayout(context);
			// ImageView iv=new ImageView(context);
			TextView tv = new TextView(context);
			tv.setText(item[position]);
			tv.setTextSize(DisplayUtil.sp2px(context, 8));
			tv.setPadding(20, 0, 0, 0);
			tv.setTextColor(context.getResources().getColor(R.color.gray_9));
			l1.setBackgroundResource(R.color.gray_e6e6e6);

			l1.addView(tv);
			return l1;
		case 7:
			LinearLayout l2 = new LinearLayout(context);
			// ImageView iv=new ImageView(context);
			TextView tv2 = new TextView(context);
			// iv.setImageResource();
			tv2.setText(item[position]);
			tv2.setTextSize(DisplayUtil.sp2px(context, 8));
			tv2.setPadding(20, 0, 0, 0);
			tv2.setTextColor(context.getResources().getColor(R.color.gray_9));
			l2.setBackgroundResource(R.color.gray_e6e6e6);
			l2.addView(tv2);
			return l2;
		default:
			l3 = new LinearLayout(context);
			ImageView iv3 = new ImageView(context);
			TextView tv3 = new TextView(context);
			iv3.setImageResource(Child_Img1[position]);
			iv3.setPadding(20, 10, 10, 10);
			tv3.setText(item[position]);
			tv3.setPadding(10, 10, 10, 10);

			LinearLayout l4 = null;

			if (position == 9 && HasUpdate == true) {
				// 在更新处显示一个new
				news = new TextView(context);
				news.setText("new");
				news.setTextColor(Color.RED);
				l4 = new LinearLayout(context);
				l4.setLayoutParams(new LinearLayout.LayoutParams(
						LinearLayout.LayoutParams.MATCH_PARENT,
						LinearLayout.LayoutParams.WRAP_CONTENT, 1.0f));
				// l4.addView(child);
			}
			l3.addView(iv3);
			l3.addView(tv3);
			l3.setGravity(Gravity.CENTER_VERTICAL);

			if (news != null && l4 != null) {
				l3.addView(l4);
				l3.addView(news);
			}
		}
		return l3;
	}

	public boolean isHasUpdate() {
		return HasUpdate;
	}

	public void setHasUpdate(boolean hasUpdate) {
		HasUpdate = hasUpdate;
	}

}
